﻿/*****************************************************************//**
 * @file    FITKAcousticsVTKGraphObjectNodes.h
 * @brief   Graph object for SEA nodes data.
 *  
 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2024-10-29
 *********************************************************************/

#ifndef __FITKAcousticsVTKGraphObjectNodes_H__
#define __FITKAcousticsVTKGraphObjectNodes_H__

#include "FITKAcousticsVTKGraphObject3D.h"

#include "FITKAcousticsVTKGraphAdaptorAPI.h"

// Forward declaration
class vtkUnstructuredGrid;
class vtkPoints;
class vtkIntArray;
class vtkGlyph3D;
class vtkCubeSource;
class vtkSelectionNode;
class vtkSelection;
class vtkExtractSelection;
class vtkIdTypeArray;
class vtkStringArray;
class FITKGraphActor2D;

class FITKAcousticsVTKGraphActor;

namespace Exchange
{
    class FITKAcousticsVTKGraphObjectSelectSEANodes;
}

namespace Acoustics
{
    class FITKAcousticsSEAModel;
    class FITKAcousticsDiscNodeList;
    class FITKAcousticsDiscModel;
}

namespace Exchange
{
    /**
     * @brief   Graph object for 'SEA nodes'.
     * @author  ChengHaotian (yeguangbaozi@foxmail.com)
     * @date    2024-10-29
     */
    class FITKACOUSTICSGRAPHADAPTORAPI FITKAcousticsVTKGraphObjectNodes : public FITKAcousticsVTKGraphObject3D
    {
        // Regist
        FITKGraphObjectRegist(FITKAcousticsVTKGraphObjectNodes, FITKAcousticsVTKGraphObject3D);
        FITKCLASS(Exchange, FITKAcousticsVTKGraphObjectNodes);

    public:
        /**
         * @brief   Constructor.
         * @param   model: The SEA model data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-29
         */
        FITKAcousticsVTKGraphObjectNodes(Acoustics::FITKAcousticsDiscNodeList* nodes);

        /**
         * @brief   Destructor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-29
         */
        ~FITKAcousticsVTKGraphObjectNodes();

        /**
         * @brief   Update all graph actors.[override]
         * @param   forceUpdate: Force update[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-29
         */
        void update(bool forceUpdate = false) override;

        /**
         * @brief   Update the visibility with data object's visibility.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-12
         */
        void updateVisibility() override;

        /**
         * @brief   Show the visible objects only.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        void updateByVisibleObjs();

        /**
         * @brief   Show the unused object only.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        void updateByUnused();

        /**
         * @brief   Show all.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        void updateByAll();

        /**
         * @brief   Show nothing.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        void updateByNone();

        /**
         * @brief    高亮渲染对象
         * @param[i] hightObjID                     高亮数据id【仅复合数据使用】
         * @param[i] type                           需要突出显示形状类型
         * @param[i] color                          高亮颜色
         * @author   BaGuijun (baguijun@163.com)
         * @date     2025-02-05
         */
        void highlight(int hightObjID = -1, FITKAcousticsVTKCommons::ShapeType type = FITKAcousticsVTKCommons::ShapeTypeNone, QColor color = QColor()) override;
        /**
         * @brief    取消高亮渲染对象
         * @param[i] hightObjID                     取消高亮数据id【仅复合数据使用】
         * @author   BaGuijun (baguijun@163.com)
         * @date     2025-02-05
         */
        void disHighlight(int hightObjID = -1) override;

        /**
         * @brief   Advanced highlight mode for highlighting part of the graph actors.[override]
         * @param   type: The type of the model need to be highlighted
         * @param   indice: The given indice of the model component need to be highlight
         * @param   color: The given color for highlighting this time[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-31
         */
        void advanceHighlight(FITKAcousticsVTKCommons::ShapeType type, QVector<int> indice, QColor color = QColor()) override;

        /**
         * @brief   Dis-highlight the graph actors if the graph object is in advanced highlighting mode.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-31
         */
        void disAdvanceHighlight() override;

        /**
         * @brief   Set if the graph object pickable mode.[override]
         * @param   mode: The pickable mode
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-31
         */
        void setPickMode(FITKAcousticsVTKCommons::ShapePickMode mode) override;

        /**
         * @brief   Get the shape id by the given shape type and VTK cell id.[override]
         * @param   vtkId: The VTK point or cell id in shape data
         * @param   topAbsShapeType: The shape type of the given ID( the same as TopAbs_ShapeEnum )
         * @return  The shape id
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-01
         */
        int getShapeIdByVTKCellId(int vtkId, FITKAcousticsVTKCommons::ShapeMeshAbsEnum topAbsShapeType) override;

        /**
         * @brief   Get the VTK point or cell indice by the given shape type and shape id.[override]
         * @param   shapeId: The shape id in shape data
         * @param   topAbsShapeType: The shape type of the given ID( the same as TopAbs_ShapeEnum )
         * @return  The cell indice[const]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-01
         */
        const QVector<int> getVTKCellIdsByShapeId(int shapeId, FITKAcousticsVTKCommons::ShapeMeshAbsEnum topAbsShapeType) override;

        /**
         * @brief   Get the world size of the glyph.
         * @return  The size
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-31
         */
        double getGlyphSize();

        /**
         * @brief   Get the VTK mesh grid by the given mesh type.[override]
         * @param   type: The shape's VTK mesh type
         * @return  The vtkDataSet object of the given type of mesh
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-31
         */
        vtkDataSet* getMesh(FITKAcousticsVTKCommons::ShapeType type) override;

        /**
         * @brief   Get the data boundary.[override]
         * @param   The bounds
         * @return  Has the bounds
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-14
         */
        bool getFixedBounds(double* bounds) override;

    private:
        /**
         * @brief   Intialize.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-29
         */
        void init();

        /**
         * @brief   Get the SEA node list from the data object.
         * @return  The SEA nodes data
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        Acoustics::FITKAcousticsDiscNodeList* getSEANodesData();

        /**
         * @brief   Update the cube size by the boundary of all SEA nodes.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-31
         */
        void updateGlyphSizeByBounds();

        /**
         * @brief   Generate the vtkDataSet for the nodes.
         * @param   nodes: The SEA nodes data
         * @return  Is the data valid
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-29
         */
        bool generateDataSet(Acoustics::FITKAcousticsDiscNodeList* nodes);

        /**
         * @brief   Generate the actor with the SEA nodes data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-29
         */
        void generateGraph();

    private:
        /**
         * @brief   The highlightor of the SEA nodes glyph.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-31
         */
        FITKAcousticsVTKGraphObjectSelectSEANodes* m_highlightSelector{ nullptr };

        /**
         * @brief   The grid data for the nodes.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-29
         */
        vtkUnstructuredGrid* m_ugrid{ nullptr };

        /**
         * @brief   The data array for the node ids.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-31
         */
        vtkIntArray* m_nodeIdArray{ nullptr };

        /**
         * @brief   The node id array name.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-31
         */
        QString m_nodeIdArrayName = "__node_id__";

        /**
         * @brief   The selection node for extract mesh grid.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        vtkSelectionNode* m_selectNode{ nullptr };

        /**
         * @brief   The selection for vtkSelectionNode.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        vtkSelection* m_section{ nullptr };

        /**
         * @brief   The mesh grid extractor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        vtkExtractSelection* m_extractSelection{ nullptr };

        /**
         * @brief   The indice array of extract id.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        vtkIdTypeArray* m_idArray{ nullptr };

        /**
         * @brief   The cube glyph for the nodes.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-29
         */
        vtkGlyph3D* m_glyph{ nullptr };

        /**
         * @brief   The cube source for the nodes glyph.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-29
         */
        vtkCubeSource* m_cubeSource{ nullptr };

        /**
         * @brief   The actor for the SEA nodes glyph.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-29
         */
        FITKAcousticsVTKGraphActor* m_fActorGlyph{ nullptr };

        /**
         * @brief   The size of the glyph source.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-29
         */
        double m_glyphSize = 20.;

        /**
         * @brief   The saved number of SEA nodes.( for update check )
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-29
         */
        int m_lastNodeCount = 0.;

        //标签
        /**
         * @brief  标签数组名称
         * @author BaGuijun (baguijun@163.com)
         * @date   2025-02-21
         */
        QString m_labelArrayName = "Labels";
        /**
         * @brief  标签文本组
         * @author BaGuijun (baguijun@163.com)
         * @date   2025-02-21
         */
        vtkStringArray* m_labelArray = nullptr;
        /**
         * @brief  标签演员
         * @author BaGuijun (baguijun@163.com)
         * @date   2025-02-21
         */
        FITKGraphActor2D* m_labelActor = nullptr;

    };
}   // namespace Exchange

#endif // __FITKAcousticsVTKGraphObjectNodes_H__
